function g=LeeLee(x)
%Function which includes all the possible gijk, i=1..n, j=1..w, and
%k=1,2,3,4. It describes all the probabilites where the ship will be after
%3 steps, if it uses the Lee-Lee strategy.
global n
global w


for i=1:n
    if i<=n-2
        g(i,1,1)=x(i,1)*x(i,2)*x(i,3);  %three in front
        g(i,1,2)=x(i,1)*x(i,2)*(1-x(i,3))+x(i,1)*(1-x(i,2))*(1-x(1,1))+(1-x(i,1))*(1-x(i+1,1))*x(i+2,1); %one in front
        g(i,1,3)=x(i,1)*(1-x(i,2))*x(1,1)+(1-x(i,1))*(1-x(i+1,1))*(1-x(i+2,1))+(1-x(i,1))*x(i+1,1)*(1-x(i+1,2)); % one behind
        g(i,1,4)=(1-x(i,1))*x(i+1,1)*x(i+1,2); % three behind
    elseif i==n-1
        g(i,1,1)=x(i,1)*x(i,2)*x(i,3);
        g(i,1,2)=x(i,1)*x(i,2)*(1-x(i,3))+x(i,1)*(1-x(i,2))*(1-x(1,1))+(1-x(i,1))*(1-x(i+1,1))*x(n,1);
        g(i,1,3)=x(i,1)*(1-x(i,2))*x(1,1)+(1-x(i,1))*(1-x(i+1,1))*(1-x(n,1))+(1-x(i,1))*x(i+1,1)*(1-x(i+1,2));
        g(i,1,4)=(1-x(i,1))*x(i+1,1)*x(i+1,2);
        
    elseif i==n
        g(i,1,1)=x(i,1)*x(i,2)*x(i,3);
        g(i,1,2)=x(i,1)*x(i,2)*(1-x(i,3))+x(i,1)*(1-x(i,2))*(1-x(1,1))+(1-x(i,1))*(1-x(n,1))*x(n,1);
        g(i,1,3)=x(i,1)*(1-x(i,2))*x(1,1)+(1-x(i,1))*(1-x(n,1))*(1-x(n,1))+(1-x(i,1))*x(n,1)*(1-x(n,2));
        g(i,1,4)=(1-x(i,1))*x(n,1)*x(n,2);
    end
    
   for j=2:w
       if j<=w-2  
           g(i,j,1)=x(i,j)*x(i,j+1)*x(i,j+2);
           g(i,j,2)=x(i,j)*x(i,j+1)*(1-x(i,j+2))+ x(i,j)*(1-x(i,j+1))*(1-x(1,1))+(1-x(i,j))*(1-x(1,1))*x(2,1);
           g(i,j,3)=x(i,j)*(1-x(i,j+1))*x(1,1)+ (1-x(i,j))*(1-x(1,1))*(1-x(2,1))+(1-x(i,j))*x(1,1)*(1-x(1,2));
           g(i,j,4)=(1-x(i,j))*x(1,1)*x(1,2);
   
       elseif j==w-1
           g(i,j,1)=x(i,j)*x(i,j+1)*x(i,w);
           g(i,j,2)=x(i,j)*x(i,j+1)*(1-x(i,w))+ x(i,j)*(1-x(i,j+1))*(1-x(1,1))+(1-x(i,j))*(1-x(1,1))*x(2,1);
           g(i,j,3)=x(i,j)*(1-x(i,j+1))*x(1,1)+ (1-x(i,j))*(1-x(1,1))*(1-x(2,1))+(1-x(i,j))*x(1,1)*(1-x(1,2));
           g(i,j,4)=(1-x(i,j))*x(1,1)*x(1,2);    
       elseif j==w
         g(i,j,1)=x(i,j)*x(i,w)*x(i,w);
           g(i,j,2)=x(i,j)*x(i,w)*(1-x(i,w))+ x(i,j)*(1-x(i,w))*(1-x(1,1))+(1-x(i,j))*(1-x(1,1))*x(2,1);
           g(i,j,3)=x(i,j)*(1-x(i,w))*x(1,1)+ (1-x(i,j))*(1-x(1,1))*(1-x(2,1))+(1-x(i,j))*x(1,1)*(1-x(1,2));
           g(i,j,4)=(1-x(i,j))*x(1,1)*x(1,2); 
        end
   end
end


end